      <div class="templatemo-content-wrapper">
        <div class="templatemo-content">
          <ul class="nav nav-tabs mytabs">
		  	 <li  class="active"><a href="<?=site_url()?>/product/index">商品列表</a></li>
		  	 <li><a href="<?=site_url()?>/product/add">添加商品</a></li>
		  </ul>
          <div class="row">
            <div class="col-md-12">

				<div class="form-inline" role="form" style="padding-bottom:20px;">
                <div class="form-group">
                  <div class="input-group">

                    <select class="form-control" id="category" name="">
                      <option value="0">全部分类</option>
                      <?php foreach ($categories as $item) { ?>
                        <option value="<?=$item['id']?>" <?php if($item['id'] ==$category) echo "selected"; ?>><?=$item['name']?></option>
                      <?php } ?>

                    </select>
                  </div>

                  <div class="input-group">

                    <select class="form-control" id="shelve" name="">
                    	<option value="-1">所有</option>
                        <option value="0" <?php if($shelve==0) echo "selected"; ?>>上架中</option>
                        <option value="1" <?php if($shelve==1) echo "selected"; ?>>下架中</option>
                    </select>
                  </div>
                  <div class="input-group">

                    <input class="form-control" type="text" id="name" placeholder="商品名称">
                  </div>
                </div>

                <button type="submit" class="btn btn-primary" id="search">搜 索</button>
              </div>
              <script type="text/javascript">
                $('#search').click(function(){
					var category = $("#category").val();
					var shelve = $("#shelve").val();
					var name = $("#name").val();
					if(name==""||name==null){
						name="empty";
					}
                	var url = "<?php echo site_url('product/index')?>";
                    window.location.href =url + "/category/"+category+ "/shelve/"+shelve+ "/name/"+name;
                })
              </script>

              <div class="table-responsive">
                <table class="table table-striped table-hover table-bordered">
                  <thead>
                    <tr>
                      <th>ID</th>
                      <th>类别</th>
                      <th>名称</th>
                      <th>日期</th>
                      <th>描述</th>
                      <th>价格</th>
                      <th>操作</th>
                    </tr>
                  </thead>
                  <tbody>
                  	<?php foreach ($products as $item):?>
                    <tr>
                      <td><?php echo $item['id'];?></td>
                      <td><?php echo $item['category'];?></td>
                      <td><?php echo $item['name'];?></td>
                      <td><?php
                      	if($item['week']==1){
                      		echo "星期一";
                      	}
                      	if($item['week']==2){
                      		echo "星期二";
                      	}
                      	if($item['week']==3){
                      		echo "星期三";
                      	}
						if($item['week']==4){
                      		echo "星期四";
                      	}
						if($item['week']==5){
                      		echo "星期五";
                      	}
                      ?></td>
                      <td><?php echo mb_substr($item['description'], 0 , 20);?>...</td>
                      <td><?php echo $item['price'].'元/'.$item['unit'];?></td>
                      <td>
                      		<a href="<?php echo site_url('product/materialindex/id/'.$item['id'])?>">配方管理</a> 
                      	    | <a href="<?php echo site_url('product/edit/id/'.$item['id'])?>" class=" ">编辑</a>
                      	    | <a href="#" class="del" data-id="<?php echo $item['id'];?>" >删除</a>
                      	    <?php if($item['shelve']==0){?>
                      	     | <a href="#" class="hidepro" data-id="<?php echo $item['id'];?>" >下架</a>
                      	    <?php }else{?>
                      	     | <a href="#" class="showpro" data-id="<?php echo $item['id'];?>" >上架</a>
                      	    <?php }?>
                      </td>
                    </tr>
                     <?php endforeach;?>
                  </tbody>
                </table>
              </div>

              <div class="pagination">
           		 <?php echo $links ;?>
         	 </div>
            </div>
          </div>
        </div>
      </div>
<script>
	$(document).ready(function() {
		$(".del").click(function() {
			if(confirm("确定要删除该商品吗？"))
			{
				var id = $(this).attr("data-id");
				$.ajax({
					url : '<?php echo site_url('product/delete')?>',
					type : "post",
					async : false,
					data : {
						'id' : id
					},
					dataType : "json",
					success : function(data) {
						if(data.code)
						{
							alert(data.msg);
							window.location.reload();
						}else{
							alert(data.msg);
						}
					}
				});
			}
		});
		$(".hidepro").click(function() {
			if(confirm("确定要下架吗？"))
			{
			var productid= $(this).attr("data-id");
			$.ajax({
				url : '<?php echo site_url('product/setstate')?>',
				type : "post",
				async : false,
				data : {
					'productid' : productid,
					'state':1
				},
				dataType : "json",
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						window.location.reload();
					}else{
						alert(data.msg);
					}
				}
			});
			}
		});
		$(".showpro").click(function() {
			if(confirm("确定要上架吗？"))
			{
			var productid = $(this).attr("data-id");
			$.ajax({
				url : '<?php echo site_url('product/setstate')?>',
				type : "post",
				async : false,
				data : {
					'productid' : productid,
					'state':0
				},
				dataType : "json",
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						window.location.reload();
					}else{
						alert(data.msg);
					}
				}
			});
			}
		});
	});
</script>
